/*
 * @Author       : NaN 353362604@qq.com
 * @Date         : 2023-05-18 14:19:28
 * @LastEditTime : 2023-06-20 14:15:53
 * @LastEditors  : NaN 353362604@qq.com
 * @FilePath     : \AdminStration\src\Common\Router\MenuNav\FirstLevel\Roles.jsx
 * @Description  :
 */
import { API_LIST } from '../../../Api/Api'
import { commonTableList } from '../Common/common'
import { AddDataButton, ModDataButton, DelDataButton, OpenTwoRouter } from '../Common/options'

export const Roles = async ({ url, OptionsEvent, Permission }) => {
    const { hostname } = window.location
    let data = {
        type: '系统设置',
        pageSize: 1000,
        params: { pageIndex: 1 },
        hideInSearch: true,
        get: API_LIST()[`get${url}Clean`],
        added: `posRoles`,
        modify: `putRoles`,
        delete: `delRoles`,
        initialValues: { isEnabled: 1 },
        options: [
            Permission?.findIndex(v => v.uuid === '23c036ba-3c6f-47f7-8293-a50026a3e683') !== -1 && (
                <AddDataButton OptionsEvent={OptionsEvent} url={url} type="primary" icon="add" title="新增角色" />
            ),
        ],
        columns: [
            commonTableList.uuid,
            { ...commonTableList.tableName, title: '角色名称' },
            { ...commonTableList.isEnabled, rules: true },
            { ...commonTableList.sortId, title: '列表排序', rules: true },
            commonTableList.remark,
            commonTableList.createUserName,
            commonTableList.createTime,
            commonTableList.updateUserName,
            commonTableList.updateTime,
            {
                title: '操作',
                valueType: 'systemOperation',
                fixed: 'right',
                width: 350,
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                render: (_, record) => {
                    return [
                        Permission.findIndex(v => v.uuid === '26dadeb1-38cd-4103-abc9-f4693f8ba81a') !== -1 && (
                            <ModDataButton
                                OptionsEvent={OptionsEvent}
                                key="modify"
                                title="修改"
                                url={url}
                                data={record}
                            />
                        ),
                        (hostname.includes('bada') ||
                            Permission.findIndex(v => v.uuid === '70adbf42-1984-49dd-973a-6e411b77102a') !== -1) && (
                            <OpenTwoRouter
                                key="TwoOne"
                                title="页面权限"
                                twoTitle="Web权限配置"
                                modal="TreeSelectModule"
                                OptionsEvent={OptionsEvent}
                                other={{
                                    page: 'RolePermissions',
                                    Permission,
                                    oneData: record,
                                }}
                            />
                        ),
                        Permission.findIndex(v => v.uuid === '4c3ebbd0-9061-47a8-abff-2b9c41f067d4') !== -1 && (
                            <OpenTwoRouter
                                key="TwoTwo"
                                title="小程序权限"
                                twoTitle="WeChat权限配置"
                                modal="TreeSelectModule"
                                OptionsEvent={OptionsEvent}
                                other={{
                                    page: 'RoleWechat',
                                    Permission,
                                    oneData: record,
                                }}
                            />
                        ),
                        Permission.findIndex(v => v.uuid === '7a635abd-5388-4b2d-954f-6822550827e3') !== -1 && (
                            <DelDataButton
                                OptionsEvent={OptionsEvent}
                                key="delete"
                                title="删除"
                                url={url}
                                uuid={record.uuid}
                            />
                        ),
                    ]
                },
            },
        ],
    }
    return data
}
